
/** 
 * post方法，对应post请求 
 * @param {String} url [请求的url地址] 
 * @param {Object} params [请求时携带的参数] 
 */
export function post(url, data){
	var header = {
		"Content-Type": "application/x-www-form-urlencoded"
	}
    return new Promise((resolve, reject) =>{ 
		 uni.request({
			url:url,
			data: data,
			method: 'POST',
			header:header,
			timeout:3000,
			success: function (res) {
				if(res.data.errorCode !== 0)
				{
					console.log(res.data);
					uni.showToast({
						title:res.data.errorMsg,
						icon: 'none'
					})
				}else if(res.data.errorCode == 0)
				{
					resolve(res.data);
				}
			},
			fail: function (err) {
				console.log(err,url);
			},
			
		})  
		//req.abort()
    });
}

export function uploadFile(url , data) {
	var header = {
		"Content-Type": "multipart/form-data"
	}
	console.log(data);
    return new Promise((resolve, reject) =>{
		uni.uploadFile({
			url: url, //仅为示例，非真实的接口地址
			files: data.files,
			fileType:'image',
			header: header,
			formData: {
				type:data.type
			},
			success: function (res) {
				resolve(res);
			},
			fail: function () {
				console.log('fail'+url)
				uni.hideLoading()
				uni.showToast({
					icon:"loading",
					title: '网络链接超时',
					mask:true,
					duration:2000
				});
			}
		})  
    });
}
export function uploadFileAvatar(url , data) {  
	var header = {
		"Content-Type": "multipart/form-data"
	}
    return new Promise((resolve, reject) =>{
		uni.uploadFile({
			url: url, //仅为示例，非真实的接口地址
			filePath:data.filePath,
			name:data.name,
			fileType:'image',
			header: header,
			formData: {
				type:data.formData.type
			},
			success: function (res) {
				console.log(res);
				resolve(res);
			},
			fail: function () {
				console.log('fail'+url)
				uni.hideLoading()
				uni.showToast({
					icon:"loading",
					title: '网络链接超时',
					mask:true,
					duration:2000
				});
			}
		})  
    });
}
